//
//  ZJFMoTaiViewController.m
//  OurTourism
//
//  Created by 张金峰 on 15/12/2.
//  Copyright © 2015年 Devil_Coming. All rights reserved.
//

#import "ZJFMoTaiViewController.h"
#import "GuideViewController.h"



@interface ZJFMoTaiViewController ()
@property (weak, nonatomic) IBOutlet UILabel *quanbu;
@property (weak, nonatomic) IBOutlet UILabel *remen;
@property (weak, nonatomic) IBOutlet UILabel *yzhou;
@property (weak, nonatomic) IBOutlet UILabel *ouzhou;
@property (weak, nonatomic) IBOutlet UILabel *dayangzhou;
@property (weak, nonatomic) IBOutlet UILabel *feizhou;
@property (weak, nonatomic) IBOutlet UILabel *meizhou;
@property (weak, nonatomic) IBOutlet UILabel *zuixin;
@property (nonatomic, assign) BOOL *panduan;
@property (nonatomic, retain) NSMutableArray *urlArr;
@property (nonatomic, strong) NSMutableArray *selectArr;
@property (nonatomic, strong) NSMutableArray *returnArr;
@property (nonatomic, strong) NSMutableArray *titleArr;
@property (nonatomic, strong) NSMutableArray *copyyTitleArr;

@property (nonatomic, strong) NSMutableArray *returnTitleArr;

@end

@implementation ZJFMoTaiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.copyyTitleArr = [NSMutableArray array];
    self.selectArr = [NSMutableArray array];
    self.returnArr = [NSMutableArray array];
    self.titleArr = [NSMutableArray array];
    self.returnTitleArr = [NSMutableArray array];
    self.urlArr = [NSMutableArray array];
    for (NSInteger i = 0; i < 8; i++) {
        [self.selectArr addObject:@"0"];
    }
    // Do any additional setup after loading the view from its nib.
    [self shezhi];
    [self url];
    
}
#pragma mark - 设置lable相关属性和手势
- (void)shezhi
{
    self.quanbu.textAlignment =NSTextAlignmentCenter;
    self.quanbu.layer.cornerRadius = 12;
    self.quanbu.layer.masksToBounds = YES;
    
    self.zuixin.textAlignment =NSTextAlignmentCenter;
    self.zuixin.layer.cornerRadius = 12;
    self.zuixin.layer.masksToBounds = YES;
    
    self.remen.textAlignment =NSTextAlignmentCenter;
    self.remen.layer.cornerRadius = 12;
    self.remen.layer.masksToBounds = YES;
    
    self.yzhou.textAlignment = NSTextAlignmentCenter;
    self.yzhou.layer.cornerRadius = 12;
    self.yzhou.layer.masksToBounds = YES;
    
    self.ouzhou.textAlignment =NSTextAlignmentCenter;
    self.ouzhou.layer.cornerRadius = 12;
    self.ouzhou.layer.masksToBounds = YES;
    
    self.meizhou.textAlignment =NSTextAlignmentCenter;
    self.meizhou.layer.cornerRadius = 12;
    self.meizhou.layer.masksToBounds = YES;
    
    self.dayangzhou.textAlignment =NSTextAlignmentCenter;
    self.dayangzhou.layer.cornerRadius = 12;
    self.dayangzhou.layer.masksToBounds = YES;
    
    self.feizhou.textAlignment =NSTextAlignmentCenter;
    self.feizhou.layer.cornerRadius = 12;
    self.feizhou.layer.masksToBounds = YES;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    self.quanbu.userInteractionEnabled = YES;
    UITapGestureRecognizer *zuixin = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    self.zuixin.userInteractionEnabled = YES;
    UITapGestureRecognizer *remen = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    self.remen.userInteractionEnabled = YES;
    UITapGestureRecognizer *yazhou = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    self.yzhou.userInteractionEnabled = YES;
    UITapGestureRecognizer *ouzhou = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    self.ouzhou.userInteractionEnabled = YES;
    UITapGestureRecognizer *meizhou = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    self.meizhou.userInteractionEnabled = YES;
    UITapGestureRecognizer *feizhou = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    self.feizhou.userInteractionEnabled = YES;
    UITapGestureRecognizer *dayangzhou = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    self.dayangzhou.userInteractionEnabled = YES;
    
    // 点击次数
    tap.numberOfTapsRequired = 1;
    // 手指个数
    tap.numberOfTouchesRequired = 1;
    // 给视图添加手势
    [self.quanbu addGestureRecognizer:tap];
    [self.zuixin addGestureRecognizer:zuixin];
    [self.remen addGestureRecognizer:remen];
    [self.yzhou addGestureRecognizer:yazhou];
    [self.ouzhou addGestureRecognizer:ouzhou];
    [self.meizhou addGestureRecognizer:meizhou];
    [self.feizhou addGestureRecognizer:feizhou];
    [self.dayangzhou addGestureRecognizer:dayangzhou];

}
- (void)url
{
    
    NSString *url1 = @"http://app6.117go.com/demo27/php/interestAction.php?start=&length=12&submit=getDiscoverDir&pid=9927&v=i6.4.2&vc=AppStore&vd=b3c1b4cf8b498fb8&lang=zh-Hans&verify=f448fd13669fbd2e6df0ff7ac1e1356d";//最新
    NSString *url2 = @"http://app6.117go.com/demo27/php/interestAction.php?start=&length=12&submit=getDiscoverDir&pid=17431&v=i6.4.2&vc=AppStore&vd=b3c1b4cf8b498fb8&lang=zh-Hans&verify=70167f27a9e8c78482cd40b158643394";//热门
    
    
    NSString *url3 = @"http://app6.117go.com/demo27/php/interestAction.php?start=&length=12&submit=getDiscoverDir&pid=23213&v=i6.4.2&vc=AppStore&vd=b3c1b4cf8b498fb8&lang=zh-Hans&verify=13bb1c5771fc2b1a97bc31402b6afd88";//亚洲
    
    NSString *url4 = @"http://app6.117go.com/demo27/php/interestAction.php?start=&length=12&submit=getDiscoverDir&pid=23423&v=i6.4.2&vc=AppStore&vd=b3c1b4cf8b498fb8&lang=zh-Hans&verify=1cb0345d6bee388e565af00571b3f71a"; //欧洲
    NSString *url5 = @"http://app6.117go.com/demo27/php/interestAction.php?start=&length=12&submit=getDiscoverDir&pid=23647&v=i6.4.2&vc=AppStore&vd=b3c1b4cf8b498fb8&lang=zh-Hans&verify=a3a627ca7c167a09e420889c5fcb2abf"; //美洲
    NSString *url6 = @"http://app6.117go.com/demo27/php/interestAction.php?start=&length=12&submit=getDiscoverDir&pid=23549&v=i6.4.2&vc=AppStore&vd=b3c1b4cf8b498fb8&lang=zh-Hans&verify=761bdfadd0a6c09f7552bdaf09d4ac11"; //非洲
    NSString *url7 = @"http://app6.117go.com/demo27/php/interestAction.php?start=&length=12&submit=getDiscoverDir&pid=23339&v=i6.4.2&vc=AppStore&vd=b3c1b4cf8b498fb8&lang=zh-Hans&verify=95a73c75f1b83fb2b66a17dde471b7ca"; //大洋洲
   self.urlArr = [@[@"1",url1, url2, url3, url4, url5, url6, url7] mutableCopy]; //url数组
    self.titleArr = [@[@"2",@"最新", @"热门", @"亚洲", @"欧洲", @"美洲", @"非洲", @"大洋洲"]mutableCopy];

    
}

- (IBAction)baocun:(UIButton *)sender {
    for (NSInteger i = 1 ; i < self.urlArr.count; i++) {
        if ([self.selectArr[i] isEqualToString:@"1"]) {
            if ([self.selectArr[0] isEqualToString:@"1"]) {
                break;
            }
            [self.returnArr addObject:self.urlArr[i]];
            [self.returnTitleArr addObject:self.titleArr[i]];
         //   NSLog(@"22222%@",self.returnArr);
        }
        
    }
    
    if ([self.selectArr[0] isEqualToString:@"1"]) {
        [self.returnArr addObjectsFromArray:self.urlArr];
        [self.returnTitleArr addObjectsFromArray:self.titleArr];
    }
    [self.delegate transmitValue:self.returnTitleArr];
    self.block(self.returnArr);
    [self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - 手势
- (void)tapAction:(UIGestureRecognizer *)tap
{
    if ([self.selectArr[tap.view.tag - 8010] isEqualToString:@"0"]) {
        [self.selectArr replaceObjectAtIndex:tap.view.tag - 8010 withObject:@"1"];
    }
    else {
        [self.selectArr replaceObjectAtIndex:tap.view.tag - 8010 withObject:@"0"];
    }
    if (tap.view.tag == 8010 && [self.selectArr[tap.view.tag - 8010] isEqualToString: @"1"]) {
        for (NSInteger i = 1; i < 8; i++) {
            [self.selectArr replaceObjectAtIndex:i withObject:@"0"];
        }
    }
    NSInteger a = 0;
    for (NSInteger i = 1; i < 8; i++) {
        if ([self.selectArr[i] isEqualToString:@"1"]) {
            a++;
        }
    }
  //  NSLog(@"%ld", a);
    
    if (a == 7) {
        for (NSInteger i = 0; i < 8; i++) {
            [self.selectArr replaceObjectAtIndex:i withObject:@"0"];
        }
        [self.selectArr replaceObjectAtIndex:0 withObject:@"1"];
    }
    
    [self changeState];
}

- (void)changeState {
    for (NSInteger i = 0; i < 8; i++) {
        UILabel *label = (UILabel *)[self.view viewWithTag:8010 + i];
        if ([self.selectArr[i] isEqualToString:@"1"]) {
            label.backgroundColor = [UIColor redColor];
        }
        else {
            label.backgroundColor = [UIColor whiteColor];
        }
    }
}
#pragma mark - 返回按钮
- (IBAction)back:(UIButton *)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
